﻿using CommandLine;
using PCore = PBIW.Core.Core;
using SysConsole = System.Console;

namespace PBIW.Console.Commands
{
    public static class ReferCommand
    {
        [Verb("refer", HelpText = "查询《周易》及其象传彖传。")]
        public sealed class Options : IOption
        {
            [Option('n', "name", HelpText = "六十四卦卦名。", Required = true)]
            public string HexagramName { get; set; } = null!;
        }

        public sealed class Executor : IExecutor<Options>
        {
            private readonly PCore core;
            public Executor(PCore core)
            {
                this.core = core;
            }

            public void Execute(Options options)
            {
                var result = this.core.GetAllText(options.HexagramName);
                if (result is null)
                {
                    SysConsole.ForegroundColor = ConsoleColor.DarkRed;
                    SysConsole.WriteLine($"未找到 {options.HexagramName} 。");
                    SysConsole.ResetColor();
                    return;
                }
                SysConsole.WriteLine($"查询成功。内容如下：");
                SysConsole.WriteLine($"===============================");
                SysConsole.WriteLine(result);
                SysConsole.WriteLine($"===============================");
                SysConsole.WriteLine($"执行完毕。");
            }
        }
    }
}
